import { RichText, Text, View } from "@tarojs/components";
import { useLoad } from "@tarojs/taro";
import moment from "moment";
import { useState } from "react";
import { getArticle } from "@/api";
import "./index.scss";


function ArticleDetail() {
    const [data, setData] = useState<any>({});
    useLoad(() => {
        // @ts-ignore
        const { id } = Taro.getCurrentInstance().router.params;
        getArticle({ id }).then((res) => {
            setData(res);
        });
    });
    return (
        <View className="articleDetail">
            <View className="detailTitle">
                <View className="title">
                    <Text>{data.contentTitle}</Text>
                </View>
                <View className="nick">
                    <Text>时间：</Text>
                    <Text>{moment(data.updateTime).format("YYYY-MM-DD")}</Text>
                </View>
            </View>
            <RichText className="text" nodes={data.content} />
        </View>
    );
}

export default ArticleDetail;
